package com.visionblue.business.ship.view.popup

import android.content.Context
import android.view.View
import android.widget.TextView
import com.visionblue.business.ship.R
import com.visionblue.business.ship.model.bean.response.ApplicationDetail
import com.visionblue.business.ship.model.enums.WasteTypeEnum
import com.visionblue.business.ship.util.FormatUtils
import com.visionblue.business.ship.util.StringUtils
import razerdp.basepopup.BasePopupWindow

/**
 * @author: xlh
 * @date: 2020-05-19 4:48 PM
 * @desc:
 */
class ShipDetailInfoPopup(
    fragment: Context,
    private val detail: ApplicationDetail
) : BasePopupWindow(fragment) {

    override fun onCreateContentView(): View {
        return createPopupById(R.layout.pop_ship_detail_info)
    }

    override fun showPopupWindow(anchorView: View) {

        val wasteTypeInfoText = detail
            .wasteInfos?.map { "${WasteTypeEnum.getWasteType(it.key)?.desc}  ${it.value.toPlainString()} 吨" }
            ?.toList()
            ?.joinToString(separator = "\n")
        findViewById<TextView>(R.id.tvPopType).text =
            if (wasteTypeInfoText.isNullOrEmpty()) "-" else wasteTypeInfoText

        findViewById<TextView>(R.id.tvPoiName).text = detail.poiName ?: "-"

        val workTime = detail.workTime
        if (workTime == null) {
            findViewById<TextView>(R.id.tvDate).text = "-"
        } else {
            val startTime = FormatUtils.formatTimeYMDHHmm(workTime)
            val endTime = FormatUtils.formatTimeHHmm(workTime + 60 * 60 * 1000)
            findViewById<TextView>(R.id.tvDate).text = "$startTime-$endTime"
        }


        findViewById<TextView>(R.id.tvLongitude).text =
            FormatUtils.formatGps(detail.longitude) ?: "-"
        findViewById<TextView>(R.id.tvLatitude).text = FormatUtils.formatGps(detail.latitude) ?: "-"

        super.showPopupWindow(anchorView)
    }


}